//
//  CarMallHeadView.m
//  carcareIOS
//
//  Created by 王然 on 16/8/16.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "CarMallHeadView.h"

#define View_Head_Height (56)
#define View_Bottom_Height (120)
@interface CarMallHeadView()

@property (nonatomic , strong) UILabel * titleL;//钣金喷漆 全场8折

@property (nonatomic , strong) UIImageView * iconIV;

@property (nonatomic , strong) UILabel * mallNameL;//门店名称

@property (nonatomic , strong) UILabel * locL;//门店地址

@property (nonatomic , strong) UILabel * callL;//门店电话

@property (nonatomic , copy) void(^cancelClick)();

@property (nonatomic , copy) void(^mallClick)();

@end

@implementation CarMallHeadView

- (instancetype)init
{
    self = [super initWithFrame:CGRectMake(0, 0, __MAIN_WIDTH, __MAIN_HEIGHT)];
    if (self) {
        
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
        [self createUI];
    }
    return self;
}
- (void)createUI
{
    UIView * headBackV = [[[UIView viewWithFrame:CGRectMake(0, 0, __MAIN_WIDTH, View_Head_Height + View_Bottom_Height)] setupOnView:self] resetBackgroundColor:[UIColor whiteColor]];
    CGFloat labelX = 12 * __MAIN_RATIO_375;
    UIImage * cancelImage = ImageNamed(@"tipsViewCancelIcon");
    UIImageView * cancelImageV = [[UIImageView imageViewWithFrame:CGRectMake(__MAIN_WIDTH - labelX - cancelImage.size.width, (View_Head_Height - cancelImage.size.height) / 2, cancelImage.size.width, cancelImage.size.height) image:cancelImage] setupOnView:headBackV];
    CGFloat btnAddW = 40;
     __weak __typeof(self) wself = self;
    [[UIButton buttonEmptyWithFrame:CGRectMake(cancelImageV.left - btnAddW, 0, cancelImage.size.width + btnAddW * 2, View_Head_Height) click:^{
        [wself animationHidden:YES];
        if (wself.cancelClick) wself.cancelClick();
    }] setupOnView:headBackV];
    
    self.titleL = [[UILabel labelWithFrame:CGRectMake(labelX, 0, __MAIN_WIDTH - labelX * 2 - cancelImageV.width, View_Head_Height) font:FONT_DEFAULT_Light(17) text:@"" textColor:COLOR_HEXSTRING(@"#ff7d0a")] setupOnView:headBackV];
    self.titleL.numberOfLines = 1;
    
    [[[UIView viewWithFrame:CGRectMake(labelX, View_Head_Height - 0.5, __MAIN_WIDTH - labelX * 2, 0.5)] setupOnView:headBackV] resetBackgroundColor:COLOR_HEXSTRING(@"#CECECE")];
    
    CGFloat iconY = 25 + View_Head_Height;
    CGFloat iconW = 76;
    CGFloat iconH = 65;
    self.iconIV = [[UIImageView imageViewWithFrame:CGRectMake(labelX, iconY, iconW, iconH) image:nil] setupOnView:headBackV];
    self.iconIV.backgroundColor = [UIColor whiteColor];
    
    CGFloat labelH = 20;
    self.mallNameL = [[UILabel labelWithFrame:CGRectMake(self.iconIV.right + labelX, self.iconIV.top, __MAIN_WIDTH - self.iconIV.right - labelX * 2, labelH) font:FONT_DEFAULT_Light(14) text:@"" textColor:[Theme wordColor]] setupOnView:headBackV];
    CGFloat labelAndLabelY = (iconH - labelH * 3) / 2;
    UIImage * locImage = ImageNamed(@"headViewLocImage");
    UIImage * callImage = ImageNamed(@"headViewCallImage");
    
    CGFloat locImageAndLabelX = 7;
    self.locL = [[UILabel labelWithFrame:CGRectMake(self.mallNameL.left + locImage.size.width + locImageAndLabelX, self.mallNameL.bottom + labelAndLabelY, self.mallNameL.width - locImage.size.width - locImageAndLabelX, self.mallNameL.height) font:FONT_DEFAULT_Light(14) text:@"" textColor:COLOR_HEXSTRING(@"#737373")] setupOnView:self];
    UIImageView * locImageV = [[UIImageView imageViewWithFrame:CGRectMake(self.mallNameL.left, self.locL.top + self.locL.height / 2  - locImage.size.height / 2, locImage.size.width, locImage.size.height) image:locImage] setupOnView:headBackV];
    
    self.callL = [[UILabel labelWithFrame:CGRectMake(self.locL.left, self.locL.bottom + labelAndLabelY, self.locL.width, self.locL.height) font:FONT_DEFAULT_Light(14) text:@"" textColor:COLOR_HEXSTRING(@"#737373")] setupOnView:headBackV];

    [[UIImageView imageViewWithFrame:CGRectMake(locImageV.left, self.callL.top + self.callL.height / 2 - callImage.size.height / 2, callImage.size.width, callImage.size.height) image:callImage] setupOnView:headBackV];
    
    
    [[UIButton buttonEmptyWithFrame:CGRectMake(0, View_Head_Height, __MAIN_HEIGHT, View_Bottom_Height) click:^{
        [wself animationHidden:YES];
        if (wself.mallClick) wself.mallClick();
    }] setupOnView:self];
}
- (void)animationHidden:(BOOL)hidden
{
    __weak __typeof(self) wself = self;
    [NSTimer scheduledTimerWithTimeInterval:0.3 block:^{
        [wself setHidden:hidden];
    } repeats:NO];
}
- (void)reloadLBSModel:(LBSStoreModel *)model mallClick:(void(^)())mallClick cancelClick:(void(^)())cancelClick
{
    if (cancelClick) self.cancelClick = cancelClick;
    if (mallClick) self.mallClick = mallClick;
    
    self.titleL.text = model.title;//@"钣金喷漆 全场8折";
    self.mallNameL.text = [NSString stringWithFormat:@"门店名称：%@",model.name];// @"门店名称：4S店汽车维修店";
    self.locL.text = model.address;//@"万荣路一路与场中路交叉路口";
    self.callL.text = model.tel;// @"021-23568989";
    
    if([model.imgUrl isNotNil])
    {
        CGFloat iconIVCenterY = self.iconIV.centerY;
        [self.iconIV setImageWithURL:[NSURL URLWithString:model.imgUrl]];
        if (self.iconIV.image) {
            self.iconIV.height = self.iconIV.width * self.iconIV.image.size.height / self.iconIV.image.size.width;
            [self.iconIV setCenterY:iconIVCenterY];
        }
    }
    
}
@end
